<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-05
 * Time: 14:49
 */

namespace app\api\validate\admin;


use LinCmsTp5\validate\BaseValidate;

class CheckAdmin extends BaseValidate
{
    protected $rule = [
        'lin_user_id' => 'require|isPositiveInteger',
        'address' => 'require|max:100',
        'coordinate' => 'require|max:50',
        'traffic' => 'array|checkTraffic',
        'phone' => 'require|max:20',
    ];

    protected $message = [
        'lin_user_id' => 'id必须为正整数',
        'address' => '请输入地址且长度不大于100字符',
        'coordinate' => '请输入坐标地址且长度不超过50',
        'traffic' => '请添加正确的交通枢纽信息',
        'phone' => '请输入联系方式且长度不大于20'
    ];


    protected function checkTraffic($value)
    {
        if(count($value) > 0) {
            foreach ($value as $v) {
                if(!$v['name']) {
                    return false;
                }
                if(!$v['traffic_id']) {
                    return false;
                }
                if(!$v['explain']) {
                    return false;
                }
            }
            return true;
        }
    }
}